﻿using System.Web;

namespace Melee.Controller.Storage
{
    public class HttpStorage : IHttpStorage
    {
        private HttpContext m_context = null;

        public HttpStorage(HttpContext context)
        {
            m_context = context;
        }

        public void Add(HttpStorageKeys key, object value)
        {
            m_context.Items[key] = value;
        }

        public bool TryRetrieve(HttpStorageKeys key, out object value)
        {
            bool exists = true;
            if (m_context.Items.Contains(key))
            {
                value = m_context.Items[key];
            }
            else
            {
                value = null;
                exists = false;
            }
            return exists;
        }

        public object Retrieve(HttpStorageKeys key)
        {
            return m_context.Items[key];
        }
        
        public bool Contains(HttpStorageKeys key)
        {
            return m_context.Items.Contains(key);
        }
    }
}
